package com.ctshk.sapp.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.BannerPositionDTO;
import com.ctshk.rpc.cms.dto.BannerPositionListDTO;
import com.ctshk.rpc.cms.req.BannerPositionAddReq;
import com.ctshk.rpc.cms.req.BannerPositionQueryReq;
import com.ctshk.rpc.cms.req.BannerPositionUpdateReq;
import com.ctshk.rpc.cms.req.SelectAllQueryReq;
import com.ctshk.rpc.cms.service.IBannerPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * banner位管理表 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "banner位管理", tags = "banner位管理")
@RestController
@RequestMapping("/banner-position")
public class BannerPositionController extends BaseController {
    @DubboReference
    private IBannerPositionService bannerPositionService;

    @ApiOperation(value = "新增banner位", notes = "新增banner位")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid BannerPositionAddReq req) {
        return bannerPositionService.add(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询banner位列表", notes = "查询banner位列表")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/getList")
    public Result<PageResponse<BannerPositionListDTO>> getList(@RequestBody @Valid BannerPositionQueryReq req) {
        return Result.success(bannerPositionService.getList(req));
    }

    @ApiOperation(value = "查询banner位列表2", notes = "查询banner位列表2")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/getListAll")
    public Result<PageResponse<BannerPositionListDTO>> getList2(@RequestBody @Valid SelectAllQueryReq req) {
        return Result.success(bannerPositionService.getList2(req));
    }

    @ApiOperation(value = "查询banner位作为下拉列表", notes = "查询banner位作为下拉列表")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getSelectList")
    public Result<List<BannerPositionDTO>> getSelectList() {
        return bannerPositionService.getSelectList();
    }

    @ApiOperation(value = "查询bnner位", notes = "查询bnner位")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getBannerPositionById/{id}")
    public Result<BannerPositionListDTO> getBannerPositionById(@PathVariable("id") Long id) {
        return bannerPositionService.getBannerPositionById(id);
    }

    @ApiOperation(value = "修改banner位", notes = "修改banner位")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid BannerPositionUpdateReq req) {
        return bannerPositionService.update(req, getCurrentUser(getRequest()));
    }
}
